﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
#region Version Info
/* ========================================================================
* 【本页面功能概述】
*
* 作者：wangjianfeng 创建时间：2012/7/31 21:03:38
* 文件名：BasePage.cs
*
* 修改者： 时间：
* 修改说明：
* ========================================================================
*/
#endregion
namespace ChinaLeg.Web.Lib
{
    public class PageBase:System.Web.UI.Page
    {
        private static readonly string LoginUrl = "/WebAdmin/Login.aspx";
        public PageBase()
        {
           //继承的是page类，所以这两个事件是从他父亲那继承来的
           this.Load += new EventHandler(this.init);
           //this.Error += new EventHandler(this.error);
        }

        protected void init(object sender,EventArgs e)
        {
            //权限判断呀身份认证呀，都放在这吧。
            if (Request.Cookies["Login"] == null||Request.Cookies["Login"].Value=="")
            {
                Response.Redirect(LoginUrl);
            }
        }

        protected void LoginOut()
        {
            HttpCookie cookie = Request.Cookies["Login"];
            cookie.Expires = DateTime.Now.AddDays(-1);
            Response.Cookies.Add(cookie);
            Response.Redirect(LoginUrl);
        }

        protected ChinaLeg.Model.Manager Cookie
        {
            get
            {
                string cookie = Request.Cookies["Login"].Value;
                ChinaLeg.Model.Manager model = new ChinaLeg.Model.Manager();
                model = Utils.Common.SerializeHelpercs.Desrialize<ChinaLeg.Model.Manager>(model, cookie);
                return model;
            }
        }

        /// <summary>
        /// 判断是否为管理员
        /// </summary>
        /// <returns></returns>
        protected bool IsAdmin()
        {
            if (Cookie.GroupId == 1)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 获取用户名
        /// </summary>
        /// <returns></returns>
        protected string GetUserName()
        {
            return Cookie.UserName;
        }
    }
}